Conversation long-polling

Conversation is based on long polling. Object “long-polling” is a part of “chat” collection. Additionally application code should prevent runs several long polling after refreshing chat page.

Table below describes long polling key points:

Event Front-end Back-end
Start process
  1. User on a chat page
  2. Ajax request runs to gets messages from server
  3. Ajax request runs to delete messages
  4. Ajax request runs get messages again
  1. Removes all registered long polling processes for current users
  2. Start new long polling process
  3. Long polling accordingly two configuration parameters: number of iterations and sleeping time (for more information please look into corresponding section)
End process
  1. Ajax response has 403 code
  2. Chat has “close” status
  1. Chat was closed
  2. Closing Browser tab was detected [1]

Footnotes

[1]Close tab or browser cause close chat only if one of the chat participant has still opened chat. In the case when all chat’s participants have closed chat — SFChat uses cron task clears garbage data.